#include <stdio.h>
#include "binarythreadtree.h"

/*InOrderTraverse threading
*/
BiThrTree pre; // global variant
void InThreading(BiThrTree p)
{
    if (p != NULL)
    {
        InThreading(p->lchild);
        if (!p->lchild)
        {
            p->LTag = Thread;
            p->lchild = pre;
        }

        if (!pre->rchild)
        {
            pre->RTag = Thread;
            pre->rchild = p;
        }

        pre = p;
        InThreading(p->rchild);
    }
}

/*InOrderTraverse_Thr*/
Status InOrderTraverse_Thr(BiThrTree T)
{
    BiThrTree p;
    p = T->lchild;
    while (p != T)
    {
        while (p->LTag == Link)
        {
            p = p->lchild;
        }
        printf("%c", p->data);
        while (p->RTag == Thread && p->rchild != T)
        {
            p = p->rchild;
            printf("%c", p->data);
        }

        p = p->rchild;
    }
    return OK;
}